<?php


namespace app\video\model;

use think\Db;
use think\Model;

class VideoModel extends Model
{
    public static function getHomeAllVideoList(){
        $videoList = array();
        $bannerList = array();
        $typeList = Db::query('select *  from t_type');
        for ($x=0; $x<count($typeList); $x++) {
            $item = Db::query('select * from t_video  where v_type_id = ? order by update_time desc limit 10',[$typeList[$x]['id']]);
            $banner = Db::query('select * from t_video  where v_type_id = ? order by update_time desc limit 1',[$typeList[$x]['id']]);
            $typeMsg = [
                "title" => $typeList[$x]['type_name'],
                "type_id" => $typeList[$x]['id'],
                "date" => $item
            ];

            $videoList[] = $typeMsg;
            $bannerList[] = $banner[0];
        }
        $msg = [
            "videoList"  => $videoList,
            "bannerList" => $bannerList
        ];
        return $msg;
    }

    public static function getAllTypeList(){
        $typeList = Db::query('select *  from t_type');
        return $typeList;
    }

    public static function getTypeVideoByID($msg){
        $videoList =  Db::query('select * from t_video  where v_type_id = ? order by update_time desc limit ?,?',[$msg['id'],($msg['page']-1)*$msg['num'],$msg['num']]);
        $count = Db::query('select count(*) from t_video  where v_type_id = ?',[$msg['id']]);
        $data = [
            'msg' => $videoList,
            'count' => $count[0]['count(*)']
        ];
        return $data;
    }

    public static function getVideoMsg($id){
        $videoMsg = Db::query('select * from t_video  where v_id = ?',[$id]);
        $urlList = Db::query('select * from t_episode  where v_id = ?',[$id]);
        $msg = $videoMsg[0];
        $msg['urlList'] = $urlList;
        return $msg;
    }

    public static function getVideoByName($msg){
        $videoList =  Db::query('select * from t_video  where v_title like ? order by update_time desc limit ?,?',['%'.$msg['name'].'%',($msg['page']-1)*$msg['num'],$msg['num']]);
        $count = Db::query('select count(*) from t_video  where v_title like ?',['%'.$msg['name'].'%']);
        $data = [
            'msg' => $videoList,
            'count' => $count[0]['count(*)']
        ];
        return $data;
    }

    public static function getBannerList(){

    }
}